﻿using NthDownload.Common.ViewModels;
using NthDownload.BL;
using NthDownload.Contracts;
using System.Windows.Data;
using NthDownload.PlaceHolders;

namespace NthDownload.ViewModels
{
    public class QueueDetailsViewModel : ViewModelScreenBase
    {
        #region Class Members

        private NthQueue _queue;
        private NthProfile _profile;
        private CompositeCollection _bandwidthProviders;

        #endregion Class Members

        #region Constructors

        public QueueDetailsViewModel(NthQueue queue, NthProfile profile)
        {
            //
            // Set Defaults
            //
            Queue = queue;
            Profile = profile;

            //
            // Create bandwidth providers composite collection
            //
            BandwidthProviders = new CompositeCollection();

            CollectionContainer bandwidthProvidersContainer = new CollectionContainer();
            bandwidthProvidersContainer.Collection = profile.BandwidthProviders;

            BandwidthProviders.Add(BandwidthProviderNoneSelection.Instance);
            BandwidthProviders.Add(bandwidthProvidersContainer);
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// The queue who's details are being shown
        /// </summary>
        public NthQueue Queue
        {
            get
            {
                return _queue;
            }
            set
            {
                _queue = value;
                NotifyOfPropertyChange(() => Queue);
            }
        }

        /// <summary>
        /// The profile the queue belongs to
        /// </summary>
        public NthProfile Profile
        {
            get
            {
                return _profile;
            }
            set
            {
                _profile = value;
                NotifyOfPropertyChange(() => Queue);
            }
        }

        /// <summary>
        /// Available bandwidth providers
        /// </summary>
        public CompositeCollection BandwidthProviders
        {
            get
            {
                return _bandwidthProviders;
            }
            set
            {
                _bandwidthProviders = value;
                NotifyOfPropertyChange(() => BandwidthProviders);
            }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Closes the dialog with a save result
        /// </summary>
        public void Save()
        {
            Result = ViewModelResults.Save;
            TryClose();
        }

        /// <summary>
        /// Closes the dialog with a save result
        /// </summary>
        public void Cancel()
        {
            Result = ViewModelResults.Cancel;
            TryClose();
        }

        #endregion Methods
    }
}
